<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商品名称" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品编号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入商品编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售模式" prop="salesModel">
        <el-select v-model="queryParams.salesModel" placeholder="请选择销售模式" clearable size="small">
          <el-option
            v-for="dict in dict.type.mall_goods_sales_model"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商品类型" prop="goodsType">
        <el-select v-model="queryParams.goodsType" placeholder="请选择商品类型" clearable size="small" >
          <el-option
            v-for="dict in dict.type.mall_goods_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="goodsList" >
      <el-table-column label="商品编号" align="center" prop="id" />
      <el-table-column label="商品名称" align="center" width="250" prop="goodsName" />
      <el-table-column label="商品图片" align="center" width="250" prop="original" >
        <template slot-scope="scope">
          <img
            :src="scope.row.original"
            style="height: 60px; margin-top: 1px; width: 60px"
          />
        </template>
      </el-table-column>

      <el-table-column label="价格" align="center" prop="price" >
        <template slot-scope="scope">
          {{$mall.unitPrice(scope.row.price, '￥')}}
        </template>
      </el-table-column>
      <el-table-column label="销售模式" align="center" prop="newsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mall_goods_sales_model" :value="scope.row.salesModel"/>
        </template>
      </el-table-column>
      <el-table-column label="商品类型" align="center" prop="goodsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mall_goods_type" :value="scope.row.goodsType"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-dropdown trigger="click">
            <span class="el-dropdown-link">
              更多<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown" >

              <el-dropdown-item  v-hasPermi="['mall-manager:goods:edit']">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleUpdate(scope.row)"

                >修改
                </el-button>
              </el-dropdown-item>
              <el-dropdown-item command="a"   v-hasPermi="['project:project:remove']">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-delete"
                  @click="handleDelete(scope.row)"

                >删除
                </el-button>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listGoods, delGoodsDraft } from "@/api/mall/goods/goods-draft";

export default {

  name: "goods",
  dicts: ['mall_goods_sales_model','mall_goods_type'],
  data() {
    return {
      id: "", //要操作的id
      loading: true, // 表单加载状态
      modalVisible: false, // 添加或编辑显示
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsName: null,
        id: null,
        storeName: null,
        marketEnable: null,
        salesModel: null,
        goodsType: null,
      },
      submitLoading: false, // 添加或编辑提交状态
      total: 0, // 表单数据总数
      goodsList: [],
      underopen: false,
      detailopen: false,
      goodsId: undefined
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询商品列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 商品修改 */
    handleUpdate(row){
      this.goodsId = row.id;
      this.$router.push({
        path: "/mall/goods/manager/operation",
        query: {
          draftId: row.id,
        }});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除？').then(function() {
        return delGoodsDraft(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  },
};
</script>

<style lang="less" scoped>
.div-zoom {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}
</style>
